package com.hyh.service.impl;

import com.hyh.bean.Menu;
import com.hyh.dao.MenuDao;
import com.hyh.dao.impl.MenuDaoImpl;
import com.hyh.service.MenuService;

import java.util.ArrayList;
import java.util.List;

public class MenuServiceImpl implements MenuService {
    private MenuDao menuDao = new MenuDaoImpl();
    @Override
    public List<Menu> getMenuList() {
        List<Menu> menuList = menuDao.getMenuList();//未分一二级
        List<Menu> newMenuList = new ArrayList();//保存分级以后的菜单
        for (Menu menu : menuList) {
            if (menu.getUpMenuId() == 0){
                List<Menu> secondList = new ArrayList<>();
                for (Menu second : menuList) {
                    if (menu.getMenuId() == second.getUpMenuId()){
                        secondList.add(second);
                    }
                }
                menu.setSecondMenuList(secondList);
                newMenuList.add(menu);
            }
        }
        return newMenuList;
    }

    @Override
    public List<Menu> getMenus(int pageIndex, int pageSize) {
        return menuDao.getMenus(pageIndex,pageSize);
    }

    @Override
    public int total() {
        return menuDao.total();
    }

    @Override
    public List<Menu> getMenuPer() {
        return menuDao.getMenuList();
    }
}
